package Job202213;

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * description:
 * author:zcx
 * lenovo
 * 时间：2022.01.16.19.57
 */
public class Job5 {
    public static void main(String[] args) {
        //姓名是张三丰，显示 张\*丰，手机号：13014577033   显示的是 130\*\*\*\*7033
        String name = "张三丰";
        System.out.println(name);
        System.out.println(name.replaceAll("(.).(.*)", "$1*$2"));

        String phone = "13014577033";
        System.out.println(phone);
        System.out.println(phone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2"));


        System.out.println(maskStr("李四六","#"));
        System.out.println(maskStr("13014577088","#"));
    }

    public static String maskStr(String str, String mask) {
        StringBuilder s = new StringBuilder(str);
        if (str.matches("^1\\d{10}$")) {
            return s.toString().replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1" + mask.repeat(4) + "$2");
        } else {
            return s.toString().replaceAll("(.).(.*)", "$1" + mask + "$2");
        }

    }
}
